/**
    算法描述：
    核心问题：
    解决所需数据结构+算法：
**/
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;

struct status
{
    /* data */
    string wd;
    int step;
    status() {
        step = 0;
    }
}start;


int main() {
    // variebles
    int n, step;
    string word, dict[101];
    bool flag = false;

    // input area
    cin >> word;
    start.wd = word;
    cin >> n;
    for (int i=0; i<n; i++)
        cin >> dict[i];

    // core code
    queue<status> q;
    q.push(start);
    while(!q.empty()) {
        status front = q.front();
        for (int i=0; i<n; i++) {
            if (front.wd.substr(0, dict[i].length()) == dict[i]) {
                front.wd = front.wd.substr(dict[i].length(), front.wd.length());
                front.step++;
                if (front.wd == "") {
                    cout << front.step-1 << endl;
                    return 0;
                }
                q.push(front);
            }
        }
        q.pop();
    }
    
    return 0;
}